//
//  UIBarButtonItem+Extension.swift
//  CKWeiBo
//
//  Created by 陈科 on 2017/1/5.
//  Copyright © 2017年 CK. All rights reserved.
//

import UIKit

//给UIBarButtonItem添加构造方法
extension UIBarButtonItem {
    convenience init(title: String, imageName: String, target: Any?, action: Selector?) {
        let btn = UIButton()
        
        btn.setImage(UIImage(named:imageName), for: .normal)
        btn.setImage(UIImage(named:imageName+"_highlighted"), for: .highlighted)
        
        btn.setTitle(title, for: .normal)
        btn.setTitleColor(UIColor.darkGray, for: .normal)
        btn.setTitleColor(UIColor.orange, for: .highlighted)
        
//        if let ac = action {
//            btn.addTarget(target, action: ac, for: .touchUpInside)
//        }
        if let ac = action {
            btn.addTarget(target, action: ac, for: .touchUpInside)
        }
        //自适应
        btn.sizeToFit()
        
       
        
        self.init()
        self.customView = btn
    }
}








